"""
管理员接口
"""

from db import modols


def register_interface(username, password):
    # 用户不存在
    if modols.Admin.select(username):
        return False, '用户已存在！'
    # 用户存在
    admin_obj = modols.Admin(username, password)
    admin_obj.save()
    return True, '注册成功'


# def login_interface(username, password):
#     # 用户不存在
#     admin_obj = modols.Admin.select(username)
#     if not admin_obj:
#         return False, '用户不存在！'
#     if admin_obj.password == password:
#         return True, '登录成功！'
#     else:
#         return False, '密码错误'


def create_school_interface(school_name, school_address, username):
    # 学校是否存在
    school_obj = modols.School.select(school_name)
    if school_obj:
        return False, '该学校以存在！'

    admin_obj = modols.Admin.select(username)
    admin_obj.create_school(school_name, school_address)
    return True, f'{school_name}学校创建成功！'


def create_course_interface(school_name, course_name, username):
    # 课程是否存在
    school_obj = modols.School.select(school_name)
    print(school_obj.__dict__)
    if course_name in school_obj.course_list:
        return False, '课程已经存在！'
    admin_obj = modols.Admin.select(username)
    admin_obj.create_course(school_obj, course_name)
    return True, f'{course_name}课程创建成功！'


def create_teacher_interface(teacher_name, username, teacher_pwd='123'):
    # 老师是否存在
    teacher_obj = modols.Teacher.select(teacher_name)
    if teacher_obj:
        return False, '该教师已经存在'

    admin_obj = modols.Admin.select(username)
    admin_obj.create_teacher(teacher_name, teacher_pwd)
    return True, f'{teacher_name}创建成功'
